package org.douxiaoban.client.activity;

import java.util.ArrayList;

import org.douxiaoban.client.R;
import org.douxiaoban.client.adapter.DouGroupNewestAdapter;
import org.douxiaoban.client.api.DouGroupApi;
import org.douxiaoban.client.tab.DouNewestTopicTab;
import org.douxiaoban.client.tab.DouTopicListTab;
import org.douxiaoban.client.util.WorkspaceView;
import org.douxiaoban.client.util.WorkspaceView.ScrollToScreenCallback;
import org.douxiaoban.client.widget.ElasticListView;
import org.douxiaoban.client.widget.ElasticListView.OnRefreshListener;
import org.douxiaoban.client.widget.TitleStyle;
import org.douxiaoban.data.DouGroupTopicData;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.FrameLayout;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 * 豆瓣小组界面，最新的话题,我发表的话题,我回复的话题-
 * 
 * @author 6a209 8:45:29 PM May 1, 2012
 */
public class DouMyGroupAct extends BaseActivity implements ScrollToScreenCallback{

	private WorkspaceView mWorkspaceGroup;

	/*我的话题布局-*/
	private LinearLayout mLyMyTopic;
	private FrameLayout mLyMyTopicBody;
	/*我的小组最新回复*/
	private DouNewestTopicTab mNewestTopic;
	/*我回复的话题*/
	private DouTopicListTab mMyReplyTopic;
	/*我发表的话题*/
	private DouTopicListTab mMySendTopic;
	
	
	private TextView mTvMyTopic;
	private TextView mTvMyReplyTopic;
	private TitleStyle mTitle; 
	
	private static final int NEWEST_INDEX = 0x00;
	private static final int MYTOPIC_INDEX = 0x01;
	@Override
	public void onCreate(Bundle bundle) {
		super.onCreate(bundle);
		mWorkspaceGroup = new WorkspaceView(this, null);
		requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
		setContentView(mWorkspaceGroup);
		getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
				R.layout.custom_title);
		LayoutInflater inflater = LayoutInflater.from(this);
		mLyMyTopic = (LinearLayout)inflater.inflate(R.layout.my_topic, null);

		mTvMyTopic = (TextView)mLyMyTopic.findViewById(R.id.my_topic_tv);
		mTvMyReplyTopic = (TextView)mLyMyTopic.findViewById(R.id.my_reply_topic_tv);
		mLyMyTopicBody = (FrameLayout)mLyMyTopic.findViewById(R.id.my_topic_body);
		
		mTvMyReplyTopic.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				if(null == mMyReplyTopic){
					mMyReplyTopic = new DouTopicListTab(DouMyGroupAct.this);
					mLyMyTopicBody.addView(mMyReplyTopic);
					mMyReplyTopic.setGetUrl(DouGroupApi.MY_REPLE_TOPIC);
					mMyReplyTopic.reqData();
				}
				mTvMyTopic.setSelected(false);
				mTvMyReplyTopic.setSelected(true);
				mMySendTopic.setVisibility(View.INVISIBLE);
				mMyReplyTopic.setVisibility(View.VISIBLE);
			}
		});
		
		mTvMyTopic.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				mMySendTopic.setVisibility(View.VISIBLE);
				mTvMyTopic.setSelected(true);
				mTvMyReplyTopic.setSelected(false);
				if(null != mMyReplyTopic){
					mMyReplyTopic.setVisibility(View.INVISIBLE);
				}
			}
		});
		
		mTvMyTopic.setSelected(true);
		
		mTitle = new TitleStyle(this);
		mTitle.initTitleStyle();
		mTitle.initPageController(2, 1);
		mTitle.setTitle(getString(R.string.group_neweast_topic));
		mNewestTopic = new DouNewestTopicTab(this);
		mWorkspaceGroup.addView(mNewestTopic);
		mWorkspaceGroup.addView(mLyMyTopic);
		mWorkspaceGroup.setScrollToScreenCallback(this);
	}
	
	
	

	@Override
	public void callback(int currentIndex) {
		mTitle.setCurrentPage(currentIndex + 1);
		if(NEWEST_INDEX == currentIndex){
			mTitle.setTitle(getString(R.string.group_neweast_topic));
		}else if(MYTOPIC_INDEX == currentIndex){
			mTitle.setTitle(getString(R.string.group_my_topic));
			if(null == mMySendTopic){
				mMySendTopic = new DouTopicListTab(this);
				mLyMyTopicBody.addView(mMySendTopic);
				mMySendTopic.setGetUrl(DouGroupApi.MY_TOPIC);
				mMySendTopic.reqData();
			}
		}
	}
}
